from classical import affinecipher, caesarcipher, vigenerecipher
from modern import cr4cipher, descipher


def test_DES():
    print("DES加密测试")
    key = b'helloDES'
    t = b'This is a secret.'
    des = descipher.DES_cipher()
    ct = des.des_encrypt(key, t)
    print("密文是", ct.hex())
    pt = des.des_decrypt(key, ct)
    print("明文是", pt)

def test_RC4():
    print("RC4加密测试")
    key = b'secret'
    t = b'hello,World!'
    rc4 = cr4cipher.RC4_cipher()
    ct = rc4.RC4_crypt(key, t)
    print("密文是", ct.hex())
    pt = rc4.RC4_crypt(key, ct)
    print("明文是", pt)

def test_caesarcipher():
    print("凯撒加密测试")
    k = 7
    t = "hello"
    c = caesarcipher.caesar_cipeher()
    c.setCaesarKey(k)
    ct = c.caesar_encrypt(t)
    print("密文是",ct)
    pt = c.caesar_decrypt(ct)
    print("明文是",pt)

def test_vigenerecipher():
    print("维吉尼亚密码测试")
    key = "key"
    t = "hello"
    v = vigenerecipher.vigenere_cipher()
    v.setVigenereKey(key)
    ct = v.vigenere_encrypt(t)
    print("密文是",ct)
    pt = v.vigenere_decrypt(ct)
    print("明文是",pt)


def test_affinecipher():
    print("仿射密码测试")
    a = 7
    b = 3
    m = 26
    f = affinecipher.affine_cipher()
    f.setKey(a, b, m)
    t = "hot"
    ct = f.affine_encrypt(t)
    print("密文是",ct)
    pt = f.affine_decrypt(ct)
    print("明文是",pt)



if __name__=='__main__':
    test_caesarcipher()
    test_affinecipher()
    test_vigenerecipher()
    test_RC4()
    test_DES()